package com.jason.kotlin.gank.ui


import android.os.Build
import androidx.annotation.RequiresApi
import androidx.databinding.BindingAdapter
import com.google.android.material.navigation.NavigationView
import com.jason.kotlin.gank.R
import com.jason.library.common.ext.showToast
import com.jason.library.common.ext.start

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
@BindingAdapter("item_select")
fun NavigationView.bindItemClick(delegate: GankHomeDelegate)  {
    setNavigationItemSelectedListener { menuItem ->
        delegate.getOwnerActivity().title = menuItem.title // 改变页面标题，标明导航状态

        delegate.getOwnerActivity().drawerLayout.closeDrawers() // 关闭导航菜单

        when (menuItem.itemId) {
            R.id.nav_home, R.id.nav_girl,  R.id.nav_category_ganhuo, R.id.nav_category_article, R.id.nav_collect -> {
                val navigationCheckedTitle = menuItem.title.toString()
                delegate.setMenuSelection(menuItem.itemId, navigationCheckedTitle)
            }
            R.id.nav_codes -> {
                menuItem.isCheckable = false
                //泡在网上的日子
                /*val intent01 = Intent(this@MainActivity, CodesActivity::class.java)
                intent01.putExtra(CodesActivity.IntentType, CodesActivity.IntentTypeName_Jcode)
                startActivity(intent01)*/
            }
            R.id.nav_cocoa_china -> {
                menuItem.isCheckable = false
                delegate.getOwnerActivity().start(RollNewsTabActivity::class.java)
                //CocoaChina
                /*val intent = Intent(this@MainActivity, CodesActivity::class.java)
                intent.putExtra(
                    CodesActivity.IntentType,
                    CodesActivity.IntentTypeName_CocoaChina
                )
                startActivity(intent)*/
            }
            R.id.nav_more -> {
                menuItem.isCheckable = false
                //更多功能
                delegate.getOwnerActivity().start(RollMoreActivity::class.java)
            }
            R.id.about -> {
                menuItem.isChecked = false // 改变item选中状态
                //跳转
                //IntentUtils.startAboutActivity(context)
            }
            R.id.setting -> {
                menuItem.isChecked = false // 改变item选中状态
                //跳转
                //IntentUtils.startSettingActivity(context)
            }
            R.id.share_app -> {
                menuItem.isChecked = false // 改变item选中状态
                //分享
                /*IntentUtils.startAppShareText(
                    context,
                    "干货营",
                    "干货营Android客户端：" + getString(R.string.download_url)
                )*/
            }
            R.id.my_qr_code -> {
                menuItem.isChecked = false // 改变item选中状态
                //我的二维码
                //IntentUtils.startQRCodeActivity(context)
            }
            R.id.my_support_pay -> {
                menuItem.isChecked = false // 改变item选中状态
                //打赏作者
                //IntentUtils.startSupportPayActivity(context)
            }
        }
        true
    }
}